package com.ruoyi.smartcity.traffic.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.smartcity.traffic.vo.EchartsOptionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.smartcity.traffic.domain.TrafficFlow;
import com.ruoyi.smartcity.traffic.service.ITrafficFlowService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 交通流量Controller
 * 
 * @author ruoyi
 * @date 2025-02-24
 */
@RestController
@RequestMapping("/smartcity/traffic/flow")
public class TrafficFlowController extends BaseController
{
    @Autowired
    private ITrafficFlowService trafficFlowService;

    //  道路名字分组
    @GetMapping("/groupByRoadName")
    public AjaxResult groupByRoadName()
    {
        List<String> roads = trafficFlowService.groupByRoadName();
        return AjaxResult.success(roads);
    }
    // 流量分析
    @GetMapping("/analysis")
    public AjaxResult analysis(String roadName)
    {
        EchartsOptionVO trafficFlows = trafficFlowService.analysis(roadName);
        return AjaxResult.success(trafficFlows);
    }

    /**
     * 查询交通流量列表
     */
    @RequiresPermissions("traffic:flow:list")
    @GetMapping("/list")
    public TableDataInfo list(TrafficFlow trafficFlow)
    {
        startPage();
        List<TrafficFlow> list = trafficFlowService.selectTrafficFlowList(trafficFlow);
        return getDataTable(list);
    }

    /**
     * 导出交通流量列表
     */
    @RequiresPermissions("traffic:flow:export")
    @Log(title = "交通流量", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrafficFlow trafficFlow)
    {
        List<TrafficFlow> list = trafficFlowService.selectTrafficFlowList(trafficFlow);
        ExcelUtil<TrafficFlow> util = new ExcelUtil<TrafficFlow>(TrafficFlow.class);
        util.exportExcel(response, list, "交通流量数据");
    }

    /**
     * 获取交通流量详细信息
     */
    @RequiresPermissions("traffic:flow:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(trafficFlowService.selectTrafficFlowById(id));
    }

    /**
     * 新增交通流量
     */
    @RequiresPermissions("traffic:flow:add")
    @Log(title = "交通流量", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrafficFlow trafficFlow)
    {
        return toAjax(trafficFlowService.insertTrafficFlow(trafficFlow));
    }

    /**
     * 修改交通流量
     */
    @RequiresPermissions("traffic:flow:edit")
    @Log(title = "交通流量", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrafficFlow trafficFlow)
    {
        return toAjax(trafficFlowService.updateTrafficFlow(trafficFlow));
    }

    /**
     * 删除交通流量
     */
    @RequiresPermissions("traffic:flow:remove")
    @Log(title = "交通流量", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(trafficFlowService.deleteTrafficFlowByIds(ids));
    }
}
